package cn.tedu.ivos.approval.controller;

import cn.tedu.ivos.approval.pojo.dto.ApplicationQueryParam;
import cn.tedu.ivos.approval.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.approval.pojo.vo.ApplicationVO;
import cn.tedu.ivos.approval.service.ApplicationService;
import cn.tedu.ivos.base.handler.JsonResult;
import com.fasterxml.jackson.annotation.JsonAlias;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "申请单模块")
@RestController
@RequestMapping("/v1/application")
public class ApplicationController{
    @Autowired
    private ApplicationService applicationService;

    @ApiOperation("添加申请单")
    @ApiImplicitParam(name = "applicationSaveParam",value = "申请单参数",required = true)
    @PostMapping("/save")
    public JsonResult save(ApplicationSaveParam applicationSaveParam){
        applicationService.save(applicationSaveParam);
        return JsonResult.ok();
    }

    @ApiOperation("查询申请单")
    @ApiImplicitParam(name = "applicationQuery",value = "查询参数",required = true)
    @GetMapping("select")
    public JsonResult select(ApplicationQueryParam applicationQuery){
        List<ApplicationVO> list = applicationService.selectApplication(applicationQuery);
        return JsonResult.ok(list);
    }
    @ApiOperation("分配用车")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vehicleId",value = "车辆id",required = true),
            @ApiImplicitParam(name = "applicationId",value = "申请单id",required = true)
    })
    @PutMapping("/distribute/{applicationId}/{vehicleId}")
    public JsonResult distributeVehicle(@PathVariable("applicationId") Long applicationId,
                                        @PathVariable("vehicleId") Long vehicleId){
        applicationService.distributeVehicle(applicationId, vehicleId);
        return JsonResult.ok();
    }
    @ApiOperation("还车")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "vehicleId",value = "车辆id",required = true),
            @ApiImplicitParam(name = "applicationId",value = "申请单id",required = true)
    })
    @PutMapping("/back/{applicationId}/{vehicleId}")
    public JsonResult backVehicle(@PathVariable("applicationId") Long applicationId,
                                  @PathVariable("vehicleId") Long vehicleId){
        applicationService.backVehicle(applicationId, vehicleId);
        return JsonResult.ok();
    }

    @ApiOperation("撤销申请单")
    @ApiImplicitParam(name = "id",value = "申请单id",required = true)
    @PutMapping("/cancel/{id}")
    public JsonResult cancel(@PathVariable("id") Long id){
        applicationService.cancel(id);
        return JsonResult.ok();
    }
}
